package com.think.oauth.user;

import springfox.documentation.service.Contact;
import springfox.documentation.service.GrantType;
import springfox.documentation.service.Parameter;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.service.TokenEndpoint;
import springfox.documentation.service.TokenRequestEndpoint;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.google.common.collect.Lists;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.OAuthBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.AuthorizationCodeGrant;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger.web.ApiKeyVehicle;
import springfox.documentation.swagger.web.SecurityConfiguration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Created by bianxh on 2019/1/21.
 */
@Configuration
@EnableSwagger2
public class SwaggerApp {
	@Bean
	public Docket createRestApi() {
		ParameterBuilder ticketPar = new ParameterBuilder();
		List<Parameter> pars = new ArrayList<>();
		ticketPar.name("access_token").description("AccessToken").modelRef(new ModelRef("string")).defaultValue("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJsb2dpblR5cGUiOjMsInVzZXJfbmFtZSI6ImFkbWluaXN0cmF0b3IiLCJzY29wZSI6WyJhbGwiXSwiZXhwIjoxNjQ5OTg5Njg2LCJ1c2VySWQiOjI2LCJhdXRob3JpdGllcyI6WyJST0xFX0FETUlOIiwiUk9MRV9OT1JNQUwiXSwianRpIjoiMWZiNzcxZjQtMDg5Yi00N2M4LTk4MjgtNTcyYjY4MTFhN2RjIiwiY2xpZW50X2lkIjoidGhpbmsifQ.vAFFs4QvVgOVKvDucFvkiG-yFxEIeR77HMgsItTqdbE")
				.parameterType("query").required(false).build(); // header中的ticket参数非必填，传空也可以
		pars.add(ticketPar.build()); // 根据每个方法名也知道当前方法在设置什么参数
		return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				// 为当前包路径
				.apis(RequestHandlerSelectors.basePackage("com.think.oauth.user")).paths(PathSelectors.any())
				.build().globalOperationParameters(pars);
	}

	// 构建 api文档的详细信息函数,注意这里的注解引用的是哪个
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				// 页面标题
				.title("用户服务接口文档")
				// 创建人
				// 版本号
				.version("1.0")
				// 描述
				.description("API 描述").build();
	}

}
